﻿// Copyright 2012 Jack Bulan (agentgeo)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GemWorkshop
{
    public partial class FlickerFreeRichTextBox : RichTextBox
    {
        private const short WM_PAINT = 0x00f;
        private bool _paint = true;

        public FlickerFreeRichTextBox()
        {
            //InitializeComponent();
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_PAINT)
            {
                if (_paint)
                {
                    base.WndProc(ref m);
                }
                else
                {
                    m.Result = IntPtr.Zero;
                }
            }
            else
            {
                base.WndProc(ref m);
            }
        }

        /// <summary>
        /// Gets or sets whether the control should be draw or not.
        /// </summary>
        public bool Paint
        {
            get { return _paint; }
            set { _paint = value; }
        }
    }

    public class FlickerFreeTextBox : TextBox
    {
        private const short WM_PAINT = 0x00f;
        private bool _paint = true;

        public FlickerFreeTextBox()
        { }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_PAINT)
            {
                if (_paint)
                {
                    base.WndProc(ref m);
                }
                else
                {
                    m.Result = IntPtr.Zero;
                }
            }
            else
            {
                base.WndProc(ref m);
            }
        }

        /// <summary>
        /// Gets or sets whether the control should be drawn or not.
        /// </summary>
        public bool Paint
        {
            get { return _paint; }
            set { _paint = value; }
        }
    }
}
